linq select distinct

94

c# linq select only unique values from list -

var uniq = allvalues.GroupBy(x => x.Id).Select(y=>y.First()).Distinct();

c# linq select only unique values from list -

var uniqueCategories =  repository.GetAllProducts()
                                  .Select(p=>p.Category)
                                  .Distinct();

select distinct linq mvc -

public static IQueryable<ProdType> GetDistinctProdType(
    this IQueryable<ProdInfo> query,
    int categoryId)
{
    return (from p in query
            where p.CatID == categoryId
            select p.Type).Distinct();
}

Comments

Submit
0 Comments